package love.contact.engine;

import love.contact.MainTabActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
    		//received when auto start after system started
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) 
        {
             	Intent newIntent = new Intent(context, MainTabActivity.class);
				newIntent.setAction("android.intent.action.MAIN");            
				newIntent.addCategory("android.intent.category.LAUNCHER");            
				newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            
				context.startActivity(newIntent);
        }
        
        //received when an app package installed,then auto start the app
        if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) 
        {
            String packageName = intent.getDataString().substring(8);
            System.out.println("---------------" + packageName);
            Intent newIntent = new Intent();
            newIntent.setClassName(packageName,packageName+ ".MainActivity");
            newIntent.setAction("android.intent.action.MAIN");             
           	newIntent.addCategory("android.intent.category.LAUNCHER");             
           	newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(newIntent);
        }
        
        //received when an app package deleted
        if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) 
        {
            System.out.println("********************************");
            //DatabaseHelper dbhelper = new DatabaseHelper();
            //dbhelper.executeSql("delete from users");
        }
    }
}